<?php
class Test extends CI_Controller{
	 function __construct()
 	{
  		parent::__construct();
  		
 	}
	function test_memcache()
	{
		$mem = new Memcache;
		$mem->connect("127.0.0.1", 11211);
	$query="select * from `mb_comments` limit 10";
	echo $query.'<br />';
	$key=md5($query);
	echo $key.'<br />';
	if(!$mem->get($key))

	{

         $conn=mysql_connect("localhost","root","lianglin") or die("连接失败");

         mysql_select_db("myblog");

         $result=mysql_query($query);

         while ($row=mysql_fetch_array($result))

         {

         	 $arr[]=$row;

         }

         $f = 'mysql';

         $mem->add($key,serialize($arr),0,30);        //mysql 查询后，插入 memcached

         $data = $arr ;

	}

	else{

        $f = 'memcache';

        $data_mem=$mem->get($key);

        $data = unserialize($data_mem);

	}

	echo $f;

	echo "<br>";

	//print_r($data);

	foreach($data as $a)

	{

                echo "number is <b><font color=#FF0000>".$a['id']."</font></b>";

                echo "<br>";

                echo "name is <b><font color=#FF0000>".$a['content']."</font></b>";

                echo "<br>";

                echo "tel is <b><font color=#FF0000>".$a['ctime']."</font></b>";

                echo "<br>";

                echo "qq is <b><font color=#FF0000>".$a['url']."</font></b>";

                echo "<br>";

                echo "email is <b><font color=#FF0000>".$a['email']."</font></b>";

                echo "<br>";

 

	}
	
	}
}
	
